home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 43 / Mac Magazin and MacEasy Magazine CD - Issue 43.iso / Software / Mobiles Büro / Newton / Newton Utilities / NewtDB 1.3 ƒ / Newton Script Spport / Newton Script.txt < prev    next >
Text File  |  1997-11-28  |  31KB  |  830 lines

  1. NewtDb Newton Script       copyright 1997 by Dave Pompea, DMP Systems  v1.12 11/28/97 
  2. ======================================================================================
  3.  
  4. 1.0 W A R N I N G
  5.  
  6. 2.0 Entering Newton Sript code
  7.     2.1 The NS window
  8.     2.2 Errors when Compiling
  9.     2.3 Errors when executing
  10.  
  11. 3.0 Newton Script 101
  12.     3.1 Variables
  13.     3.2 Math
  14.     3.3 Saving Vars
  15.     3.4 Conditional Statements
  16.     3.5 Detecting Errors
  17.     3.6 Soups, Cursors and Entries
  18.     3.7 Looping
  19.  
  20.  
  21. 4.0 Predefined Functions and Methods
  22.  
  23. 4.1 Database functions
  24.     4.1.1 DbNameToNumber
  25.     4.1.2 GetFieldNames
  26.     4.1.3 GetCursor
  27.     4.1.4 GetEntry
  28.     4.1.5 NextEntry
  29.     4.1.6 ResetCursor
  30.     4.1.7 GetDbIndirectRecord
  31.     4.1.8    MatchData
  32.     4.1.9 SaveEntry
  33.  
  34. 4.2 Field Functions
  35.  4.2.1 FieldNameToNumber
  36.     4.2.2 GetField
  37.     4.2.3 SetField
  38.  
  39. 4.3 Misc. functions
  40.     4.3.1 FormDateString
  41.     4.3.2 Show
  42.     4.3.3 ShowError
  43.     4.3.4    ToString
  44.  4.3.5 ToNumber
  45.     4.3.6 SaveNsVar
  46.     4.3.7 UpdateDisplay
  47.  
  48. 4.4 ROM functions
  49.  4.4.1 SubStr
  50.  4.4.2 HourMinute
  51.  
  52. 5.0 Getting information from the Names soup
  53.     5.1 GetNamesInfo
  54.  
  55. 6.0 Making a Note in the NotePad
  56.  6.1 MakeNote
  57.  
  58. 7.0 Other built in variables 
  59.     7.1 ButtonHit
  60.     7.2 CurrentDbCursor
  61.     7.3 CurrentDb
  62.     7.4 CurrentDbEntry
  63.     7.5 DataformClick
  64.     7.6 FirstTimeFlag
  65.     7.7 LastEditField,LastEditDb
  66.     7.8 NsError
  67.     7.9 NSDontClick
  68.     7.10 RecordAction
  69.     7.11 UpdateFromNS
  70.  
  71. Appendex A - NsError values
  72. Appendex B - Release notes
  73.  
  74.  
  75.  
  76. 1.0 W A R N I N G
  77. =================
  78.  
  79. If you put Newton Script objects on your screens, the previous version  (v1.25 and below) of NewtDb and UtilityDb will not be able to be used as you will get errors.   So, make a backup of your Newton before experimenting with Newton Script.  Just in case.
  80.  
  81. You can, of course, delete all Newton Script Screen Objects and then all will be well if using a previous version of NewtDb or UtilityDb.
  82.  
  83.  
  84. 2.0 Entering Newton Sript code
  85. ==============================
  86.  
  87. 2.1 The NS window
  88. -----------------
  89.  
  90. You make a NS Screen Object by pressing the 'N' button and then selecting "Newton Script". Press the 'E' (for Edit) or double tap the object to open the edit window for it.
  91.  
  92. Button Text: Define a Label to show up on the screen.
  93.  
  94. Run Script Always: Check this to have the script execute whenever the screen is updated when viewing different records. i.e., when scrolling, after an edit, changing back to Detail View . If not checked, the code will be run only when the NS button is pressed. If you have set the variable NSDontClick to TRUE then the script will not be run when the button is pressed. 
  95.  
  96. Code:  Enter your NS code here.
  97.  
  98. Db/Fl button: Press to see a list of all databases and the fields in them. Select a database and it will be pasted into the code. Then, on the next press of this button, the fields for that database will show. Note: If you just wanted to first see the fields of a database, press UnDo to delete the database name text that was pasted into the code.
  99.  
  100. func(x) button:  Press the to see all the functions  / variables / other defined so you don't have to type them in. Select from this list to paste it at the insertion point.
  101.  
  102. Check button: Use this to check your code for syntax errors. If there are any, the line number will be shown. The line number is not as you see the lines of code on the screen, but rather where you have put a <cr> (return) at the end of each line.
  103.  
  104. [A] button: Used to select all text. Note: I discovered that you can also select all text using the TAB key.
  105.  
  106. Up and Down arrows: Removed in v1.26b3. Use Newton's scroll arrows.
  107.  
  108.  
  109. 2.2 Errors when Compiling
  110. -------------------------
  111.  
  112. When you press the 'check' button or close the Newton Script window, the code is compiled. If there are any errors, the possible error line will be selected and an error message displayed. Sometimes the error message will tell you exactly what is wrong. Sometimes not exactly. The messages are the same as a programmer sees.
  113.  
  114. The line selected may or may not be the line in error. Sometimes it's the line above the selected line as the compiler is still scanning text is search of a valid line of code. 
  115.  
  116. If the error text is the last line, then the error may be well above it. Some causes are unmatched quotes, unbalanced parentheses or a missing END statement. 
  117.  
  118. 2.3 Errors when executing
  119. -------------------------
  120.  
  121. When your code executes, the NsError variable will be NIL until a detectable error happens. Then, when a detectable error happens, NsError will be set to a number and the data returned from the function will be NIL if an object is expected to be returned, 0 if a number is expected and an empty string ("") if a string is expected.
  122.  
  123. When an undetectable error happens, you will get the normal error box on the screen with the Newton Script title you gave your code, the Newton O/S error number and for common errors, an explantaion of the error. You also might get the variable or function name that is the cause of the error. You might also get the last NsError code that was encountered, if there was one.
  124.  
  125. Until your code is fully debuged, you might want to sprinkle :show("step_xxx_Im_here") statements in your code so that you can see what the last executed command was.
  126.  
  127. Another way to see what statement is in error is to set the NsError var yourself to a negative number after each statement. That way, the error box will show you that number and you'll know which statement caused the error. But remember that a detectable error will set the NsError variable to a positive number.
  128.  
  129. Example:
  130.  
  131. local X := "test";
  132. NsError := -1;
  133. X := X + 1;
  134. NsError := -2;
  135. X := Z + 1;                // this would cause an error if Z is not defined, ie NIL. It will show "NsError = -2" in the error box.
  136.  
  137.  
  138.  
  139.  
  140. 3.0 Newton Script 101
  141. =====================
  142.  
  143. For basic Newton Script information, surf over to Fundamentals of NewtonScript at http://www.newton-inc.com/dev/techinfo/ProgNewtUsingMac/ProgNewt-77.html and Programming for the Newton at http://www.newton-inc.com/dev/techinfo/ProgNewtUsingMac/ProgNewt-1.html
  144.  
  145.  
  146. All logical lines of code end in a ';' - a semi colon.
  147.  
  148. Comments in code are proceeded with '//' - two slashes. This will comment out anything up to the next <cr>.
  149.  
  150. Assignments use ':=' to separate left and right sides:      ATotal := ATotal + 1;
  151.  
  152. To put two (or more) vars that hold text into one var, use the '&' operator:  a := "me";  b := " and ";  c:= "you";  d := a & b & c;
  153. D now contains "me and you".
  154.  
  155.  
  156. Functions and methods (unless they are Global, ie in the Newton Rom) have a colon if front of them:
  157.  
  158. :Show("some_text");
  159.  
  160.  
  161.  
  162.  
  163. 3. 1 Variables
  164. --------------
  165.  
  166. Variables start with a letter, have NO embedded spaces and are NOT case sensitive. You cannot use a '.' (period) in a variable name. 
  167.  
  168. If you need (and you will) variables in your code, define them with a 'Local' statement: 
  169. Local SomeVar;
  170. Local SomeVar := nil;
  171. Local SomeVar := 10;
  172.  
  173. Local variables are not saved between executions of your code. To save variables you need to put them in a frame that will be saved, even after closing NewtDb. You do not have to "type" type variables. In other words, you do not have to define a variable as string (text) or integer or real. A variable can hold any type of information.
  174.  
  175.  
  176. 3.2 Math
  177. --------
  178.  
  179. All the normal arithmetic operators are in Newton Script.
  180.  
  181.  
  182.  
  183. 3.3 Saving Vars
  184. ---------------
  185.  
  186. To save a variable so that it's value is available the next time the code is executed, attach it to the variable NSvar. NSvar is a frame (kind of like a record in Pascal or a structure in C ) that can hold as many variables (up to 32k bytes in size) as you want. Since the NSvar is accessable to all your Newton Script code Screen Objects, you can set information in it in one code script and get at that information in another code script.
  187.  
  188. To save your attached variables, do a :SaveNsVar(); method at the end of your script. If you do not, then your vriables may not be saved.  The NSvar frame is actually saved in the NewtDb Preferences soup entry.
  189.  
  190. Example:
  191.  
  192. Local PartTotal;                       // declare the var
  193. If NSvar.PTotal <> nil then      // PartTotal has  been saved as it is defined (ie not NIL).
  194.      PartTotal := NSvar.PTotal;  // so get it's value
  195.   else                           // otherwise ...
  196.      PartTotal := 0;             // initialize it
  197. // do some calculations here
  198. NSvar.PTotal := PartTotal;       // set the var into the NSvar frame
  199. :SaveNsVar();                    // tell NewtDb to save it
  200.  
  201.  
  202.  
  203. You attach a variable to the NSvar variable by using the dot constructor:
  204.  
  205. NSvar.PTotal := PartTotal;    // set the var into the NSvar frame
  206.  
  207. You can reference the saved variable the same way, but you realy should check for its existance first:
  208.  
  209. If NSvar.PTotal <> nil then PartTotal := NSvar.PTotal;
  210.  
  211.  
  212.  
  213. 3.4 Conditional Statements
  214. --------------------------
  215.  
  216. They have the form of:
  217.  
  218. IF expression THEN statement {ELSE statement}
  219.  
  220.  
  221. Where expression can be a logical comparison of two variables or just one variable evaluated to see if it's true.
  222.  
  223. "statement" can be just one , single statement or multiple statement surrounded by "BEGIN" and "END;"
  224. The BEGIN / END; pair indicate that more than one statement is to be executed.
  225.  
  226. Only integers and symbols can be compared for equality. To compare text use the function StrEqual(a,b), which returns TRUE if both text strings are the same. StrEqual is not case sensitive. 
  227.  
  228. Examples:
  229.  
  230. If MyVar then count := count +1;    // checks that 'MyVar' is not nil
  231.  
  232. If NOT MyVar then count := count +1;    // checks that 'MyVar' is  nil
  233.  
  234. If MyVar = 3 then  count := count +1;  
  235.  
  236. If MyVar = 3 then  count := count +1;  else count = 0;
  237.  
  238. If MyVar = 3 then  
  239.    begin
  240.         count := count +1;  
  241.         total := total + item;
  242.    end;
  243.  
  244. If (MyVar = 3) and (item > 100) then  
  245.    begin
  246.         count := count +1;  
  247.         total := total + item;
  248.    end;
  249.    else begin
  250.       count := 0;
  251.       total := 0;
  252.    end;
  253.  
  254.  
  255. Relational operators include: =, <>, >, <, <=, and >=  .
  256. You can use AND or OR to group expressions. You can use the keyword NOT to negate.
  257.  
  258. If you use an ELSE statment, it is tied to the last IF statment before it.
  259.  
  260.  
  261. 3.5 Detecting Errors
  262. --------------------
  263.  
  264. The built in variable NSError will be normally be NIL if all is OK.  If one of the built in function spots an error in the parameters you pass it, it willbne set to a numer (ie NOT NIL)  If it is not NIL (an error occured) , you will need to reset it to nil for later use inside the script to detect later errors.
  265.  
  266. See the NsError number list at the end of this document.
  267.  
  268. Example:
  269. local aDbNumber := 999;     // bogus as  database #999 surely does not exist
  270. :GetFieldNames(aDbNumber);   // try to get the field names of Db #999, this will set NSError to 2.
  271. if NSError then .....       // check for the error, it will be non NIL if there has been an error.
  272.  
  273. NSError will not be NIL as the function GetFieldNames checks the DbNumber and 999 is surely more than the maximum allowed.
  274.  
  275.  
  276. 3.6 Soups, Cursors and Entries
  277. ------------------------------
  278.  
  279. We all know what a Soup is, right ? It's that thing in the Storage folder (in Extras) that holds information. You'll need to know the Database Number to access the records in the soups. The Database number is the one you selected when you made the database. Database numbers start at 0 and go to 15 (Right now. In the future it will be 63). You can also use the Database Name to find out the number.
  280.  
  281. To get a record from the database, you need to tell Newton which one you would like to work with. This is called a Cursor. Like the cursor on your screen, it points to a record in a soup.
  282.  
  283. But a Cursor only points to a record. To get that record, it needs be retrieved. When you retrieve a record from where the Cursor is pointing, it's called an Entry. This entry is what you work with to get at the data in the record.
  284.  
  285.  
  286. So,  to get the first record, it would look something like this:
  287.  
  288. Local MyDatabaseNumber  :=  :DbNameToNumber("PartsDb");         // get the Db number from it name
  289. Local MyCursor := :GetCursor(MyDatabaseNumber,0 );    //get a cursor for the database using Index 0
  290. Local MyEntry := :GetEntry(MyCursor);      // get the record that the cursor is pointing to
  291.  
  292.  
  293. 'MyEntry' now contains the first record in the database and can be used by other functions to get or change the data in each field:
  294.  
  295. local FieldNumber := 2;
  296. Local name := :GetField(MyEntry, FieldNumber);   //  gets the data from field #2 and put it in var 'name'
  297.  
  298. To get subsequent records use:
  299.  
  300. MyEntry :=  :NextEntry(MyCursor);     // this will point the cursor at the next record and fetch it
  301.  
  302. To test if you have come to the end of the database (no more records) , see if the Entry is not nil:
  303.  
  304. If MyEntry  then  ....     // if there is a record, then this will evaluate to other than NIL
  305.  
  306.  
  307. 3.7 Looping
  308. -----------
  309.  
  310. Newton Script doesn't have a GOTO Label type function, so you have to use the WHILE DO  construct to loop.
  311.  
  312. Example:
  313.  
  314. x := 0
  315. While x < 10 do
  316.     begin
  317.         x := x + 1;
  318.        total := total + item;
  319.    end;
  320.  
  321. Or you can use a FOR loop. Which works just like a FOR loop in Basic and is kind of close to FORTRAN and, thank goodness, nothing like C.
  322.  
  323. Example:
  324.  
  325. For i := 1 to 10 by 1 do
  326.     begin
  327.         x := x + 1;
  328.        total := total + item;
  329.    end;
  330.  
  331. The "by 1" is optional. The above will loop setting the var 'i' to 1, incrementing it at the end, until it reaches 10.
  332.  
  333.  
  334.  
  335.  
  336.  
  337. 4.0 Predefined Functions and Methods
  338. ====================================
  339.  
  340. There are many functions defined for you so that you don't have to know how records are stored. Functions return a result. Methods do not. Both must have their name proceeded by a ':' (colon) or you will get a -48808 error (Undefined global function) when the code is run. 
  341.  
  342. Each function is shown as it is entered with any variables needed, an explanation of the function and the variables types needed and the data (if any) returned.
  343.  
  344. 4.1 Database functions
  345. ----------------------
  346.  
  347. 4.1.1 DbNameToNumber
  348.  
  349. :DbNameToNumber(DbName)
  350.  
  351. Returns:  the Number of a database when supplied the name of it.
  352. DbName: a text string
  353.  
  354.  
  355. 4.1.2 GetFieldNames
  356.  
  357. :GetFieldNames(DbNumber)
  358.  
  359. Returns: an array (FieldNameArray) of field names of a database.
  360. DbNumber: a database number
  361.  
  362.  
  363. 4.1.3 GetCursor
  364.  
  365. :GetCursor(DbNumber, IndexNumber)
  366.  
  367. Returns: a Cursor object
  368. DbNumber: a database number
  369. IndexNumber:  an index number (0-2, currently) 
  370.  
  371.  
  372. 4.1.4 GetEntry
  373.  
  374. :GetEntry(DbCursor)
  375.  
  376. Used to fetch the current record that is pointed to by the cursor.
  377.  
  378. Returns: a database record
  379. DbCursor:  a Cursor object
  380.  
  381.  
  382. 4.1.5 NextEntry
  383.  
  384. :NextEntry(DbCursor)
  385.  
  386. Advances the cursor to the next record in the database and gets that record.
  387.  
  388. Returns:  the next database record
  389. DbCursor:  a Cursor object
  390.  
  391.  
  392. 4.1.6 ResetCursor
  393.  
  394. :ResetCursor(DbCursor)
  395.  
  396. Resets the Cursor so that it points to the first record in a database.
  397. DbCursor:  a Cursor object
  398.  
  399.  
  400. 4.1.7 GetDbIndirectRecord
  401.  
  402. :GetDbIndirectRecord(DbNumber, MatchFieldNumber, MatchDataStr)
  403.  
  404. Fetches any record from any database. The database (DbNumber) is searched to find a record that has MatchDataStr in its MatchFieldNumber field.
  405.  
  406. Returns: A frame the consists of DbEntry and DbCursor slots:  (DbEntry: xxxx , DbCursor: yyyy). If there is not a match then both DbEntry and DbCursor are set to nil.
  407.  
  408. DbNumber: The database to search in.
  409. MatchFieldNumber: The field number to use for matching data.
  410. MatchDataStr: The data to match in MatchFieldNumber. It is not case sensitive.
  411. Further entries (as referenced by DbCursor returned) the will NOT be qualified per the original match data. However, if the MatchFieldNumber is an index then further records returned by using the DbCursor will be sorted as specified by the index.
  412.  
  413. Note: This function has changed since the original (v1.26b1) release. The result is now a frame and the DbCursor var is NOT passed.
  414.  
  415. Example:
  416.  
  417. local DbNumber := 6;
  418. local MatchFieldNumber := 0;
  419. local MatchDataStr := "D";
  420. local MyFrame := :GetDbIndirectRecord(DbNumber, MatchFieldNumber, MatchDataStr)
  421.  
  422. local MyDbEntry := MyFrame.DbEntry;   // get the record returned
  423. local MyDbCursor := MyFrame.DbCursor;  // get the cursor returned
  424.  
  425.  
  426. The above searches Db #6 in field #0 for data starting with a "D". If found, then the record entry and cursor to it are returned in MyFrame. 
  427.  
  428.  
  429. 4.1.8    MatchData
  430.  
  431. :MatchData(DbEntry, FieldNumber, MatchDataStr)
  432.  
  433. Use to check if a record (DbEntry) contains the data (MatchDataStr) in field:  FieldNumber.
  434.  
  435. Returns: NIL if MatchDataStr is NOT the data in the  field (FieldNumber), otherwise TRUE.
  436. DbEntry: a database record
  437. FieldNumber: the field number to use
  438. MatchDataStr: the text data to match
  439.  
  440.  
  441. 4.1.9 SaveEntry
  442.  
  443. :SaveEntry(DbEntry)
  444.  
  445.  
  446. Sets a flag to have NewtDb save the record to the soup. If you do not call this method, any changed data may not be saved.
  447.  
  448. DbEntry: the database record
  449.  
  450.  
  451. 4.2 Field Functions
  452.  
  453. 4.2.1 FieldNameToNumber
  454.  
  455. :FieldNameToNumber(FieldNameArray,FieldName)
  456.  
  457. Lets you get a field number of any database when you provide the text name of the field.
  458.  
  459. Returns: field number
  460. FieldNameArray: Array from GetFieldNames()
  461. FieldName: text name of a field
  462.  
  463.  
  464. 4.2.2 GetField
  465.  
  466. :GetField(DbEntry, FieldNumber)
  467.  
  468. Extracts the field data from a database record.
  469.  
  470. Returns: The field data from a record
  471. DbEntry: a database record
  472. FieldNumber: the field number of the data to get
  473.  
  474.  
  475. 4.2.3 SetField
  476.  
  477. :SetField(DbNumber, DbEntry, FieldNumber, aString)
  478.  
  479. Puts data into a database record.
  480.  
  481. DbNumber: The database number
  482. DbEntry: The database record
  483. FieldNumber: the field number of where to put the data into
  484. aString: the data  to be put in the record
  485.  
  486.  
  487.  
  488.  
  489. 4.3 Misc. functions
  490.  
  491. 4.3.1 FormDateString
  492.  
  493. :FormDateString(time())
  494.  
  495.  
  496. Returns a Date text string, formatted as you have specified in NewtDb->[i]->prefs->Date Format.
  497. Normally you feed if a "time()" method. Time() returns time in minutes since 1904. If you need to calculate times, use  :ToString(time()) and put that text number in a field. Then use that number ( :ToNumber(aString)  ) to convert to a number, calculate a new date, and put the date on screen in the NS object.
  498.  
  499.  
  500. 4.3.2 Show
  501.  
  502. :Show(aString)
  503.  
  504. Takes a text string (aString) and puts that text into the Newton Script Button on the screen. 
  505.  
  506.  
  507. 4.3.3 ShowError
  508.  
  509. :ShowError(aString)
  510.  
  511. Takes a text string (aString) and makes it into an Error Dialog box. Like all the -xxxxx errors you see that pop up when a program goes kablooie.
  512.  
  513.  
  514. 4.3.4    ToString
  515.  
  516. :ToString(aNumber)
  517.  
  518.  
  519. Converts a number to a text string. NewtDb stores all data as text. After a calculation, convert a number to text with this if you want to put it in a record or display.
  520. Returns: a text string
  521. aNumber: a number. It can be a real or integer.
  522.  
  523.  
  524. 4.3.5 ToNumber
  525.  
  526. :ToNumber(aString)
  527.  
  528. Converts text to a number. NewtDb stores all data as text. To use in a calculation, you must convert it to a number.
  529. Returns: a number. It may be real (123.456) or an integer (123) depending on the data
  530. aString: text form of a number: "123.456" , "-3", "1e22"
  531.  
  532. If a blank (empty) string is passed, a zero is returned.
  533.  
  534.  
  535. 4.3.6 SaveNsVar
  536.  
  537. :SaveNsVar()
  538.  
  539. Sets the flag telling NewtDb to save any Newton Script (NOT Local vars) vars (NsVar.xxx) to soup so they can be used the next time NewtDb is started. See  Saving Vars.
  540.  
  541.  
  542. 4.3.7 UpdateDisplay
  543.  
  544. :UpdateDisplay()
  545.  
  546. Forces NewtDb to update the screen. Just as if you pressed a scroll button to get another record on the screen or after an Edit.  Useful ONLY when you have changed a value in a Database field that is displayed on the screen and you want the screen to show it. Be sure to use :SaveEntry(DbEntry)  first !
  547.  
  548. Other Newton Script Screen Objects will be executed when UpdateDisplay is executed. The script from which UpdateDisplay was called in will not be executed again. Otherwise a loop would result.
  549.  
  550. Everytime UpdateDisplay is executed, all the data on the screen is updated so doing this can be an expensive CPU cycle eater. If you have multiple scripts that need to UpdateDisplay, try putting only one UpdateDisplay in the last script to be executed. You determine the order of  Screen Objects being updated by using the Move to Front / Back button in UtilityDb. Front most objects are executed / updated last.
  551.  
  552. If you do not want the other Newton Script objects to execute when UpdateDisplay is called, put a test in the scripts for the variable UpdateFromNS which is set to TRUE if an UpdateDisplay is in effect:
  553.  
  554. If UpdateFromNS then return;     // no need to run this script as screen is being refreshed by another Newton Script Object.
  555.  
  556.  
  557. 4.4 ROM functions
  558.  
  559. 4.4.1 SubStr
  560.  
  561. SubStr(aString,startPos, NumberChars)
  562.  
  563. Returns a part of a string(text) var. Works just like MID$ in Basic.
  564.  
  565. aString - a text string
  566. startPos - the starting position in the string to start extracting from. Strings start at 0.
  567. NumberChars - number of characters to extract. Use nil to get all characters to the end of the string.
  568.  
  569. Examples:
  570.  
  571. SubStr("abcdefg", 2,2) returns "cd"
  572. SubStr("abcdefg", 2,nil) returns "cdedf"
  573.  
  574.  
  575. 4.4.2 HourHinute
  576.  
  577. HourMinute(time)
  578.  
  579. Returns a string that has the time formated as "HH:MM Xm" or whatever your local is set to.
  580.  
  581. time - a valid time number. Use time() for the current time.
  582.  
  583.  
  584.  
  585. 5.0 Getting information from the Names soup
  586.  
  587. 5.1 GetNamesInfo
  588.  
  589. :GetNamesInfo(MatchStr)
  590.  
  591. Gets a record from the Names soup
  592.  
  593. Returns: a Names soup frame or nil if not found.
  594. MatchStr: text that is used to match an entry in the Names soup. This data is matched to the 'sorton slot , which is normally the Name or Company.
  595.  
  596. The data in this frame is:
  597.  
  598. [see the Names Soup Format document for details]
  599.  
  600. Example:
  601.  
  602. Local aNameRecord := :GetNamesInfo("Pompea"); // that's me you're looking up
  603. local aCity := aNameRecord.city;  // get the city for me
  604. :Show("Dave lives in " & aCity);  // show it on the screen, where the NS button is.
  605.  
  606.  
  607.  
  608.  
  609. 6.0 Making a Note in the NotePad
  610.  
  611. 6.1 MakeNote
  612.  
  613. :MakeNote(aString)
  614.  
  615. Takes aString and makes a Note in the NotePad of it. You can put up to 8,000 characters of text into a Note. You may include <cr>'s (unix new lines) by using a \n in the text and tabs as  \t . Please see the example code for formatting data for the NotePad when you use tabs.
  616.  
  617.  
  618.  
  619.  
  620. 7.0 Other built in items
  621. ========================
  622.  
  623. 7.1 ButtonHit
  624.  
  625. ButtonHit 
  626.  
  627. A Var that indicates that this Newton Script code is being executed because the user pressed  it's button on the screen. Also see: NSDontClick.
  628.  
  629. 7.2 CurrentDbCursor
  630.  
  631. CurrentDbCursor
  632.  
  633. CurrentDbCursor is a variable of type  DbCursor and is the same one used for the record being show on the screen. It is the same as ":GetCursor(DbNumber, IndexNumber)" except you don't have to know the database number and the index is the same as you have set on the screen. And it will only fetch records qualified by  your on screen Query , if you have the Query! set on.
  634.  
  635. CurrentDbCursor initially points to the current screen record, so you should do something like:
  636.  
  637. local myCursor := CurrentDbCursor;
  638.  :ResetCursor(myCursor);            // now points to the first record in the datatbase, or first matching record if Query is on.
  639.  
  640. If you need to always know the current screen record, make a copy of it first:
  641.  
  642. local myCursor := CurrentDbCursor:clone();  // makes a copy of the screen cursor, leaving CurrentDbCursor pointing at current record
  643.  :ResetCursor(myCursor);            // now points to the first record in the datatbase, or first matching record if Query is on.
  644.  
  645. Note: Do Not use CurrentDbCursor in a PickActionScript or any other defered / delayed call as it's not valid after the main code executes. If you realy do need it under these conditions, copy it to the NSVar frame and remember to nil out that var after use.
  646.  
  647.  
  648. 7.3 CurrentDb
  649.  
  650. CurrentDb
  651.  
  652. A var that holds the number of the database being viewed on the screen. Can be used in place of:
  653.  
  654. local TheDb := :DbNameToNumber("current_screen_Db_Name")
  655.  
  656. when you are working with records in the current screen being displayed and you don't want to hard code the database number.
  657.  
  658.  
  659. 7.4 CurrentDbEntry
  660.  
  661. CurrentDbEntry
  662.  
  663.  
  664. A var holds the current database record that is seen on the screen.
  665. You can use this in place of DbEntry as shown in the following examples:
  666.  
  667. local DbCursor := CurrentDbCursor;
  668. local DbEntry := :GetEntry(DbCursor);
  669.  
  670. or
  671.  
  672. local DbCursor := :GetCursor(DbNumber,index);
  673. local DbEntry := :GetEntry(DbCursor);
  674.  
  675. or (even more verbose)
  676.  
  677. local index := 0;
  678. local DbNumber := :DbNameToNumber("Names Db");
  679. local DbCursor := :GetCursor(DbNumber,index);
  680. local DbEntry := :GetEntry(DbCursor);
  681.  
  682.  
  683. in all above cases the DbEntry var is the same as the CurrentDbEntry var.
  684.  
  685.  
  686. 7.5 DataformClick
  687.  
  688. DataformClick
  689.  
  690.  
  691. A variable that can be examined to see if any field on the screen is being edited. DataformClick will be equal to 1 if a field is being edited, 0 if not.
  692.  
  693.  
  694. 7.6 FirstTimeFlag
  695.  
  696. FirstTimeFlag
  697.  
  698. A var that is set to True when the Newton Script code is executed for the first time. i.e.. when the screen containing the NS object is first viewed. It is set to NIL afterwards. NOTE:  NewtDb caches screens. If a screen is unloaded, then loading it again will set the FirstTimeFlag again. This may change in the future so that FirstTimeFlag is TRUE only once.
  699.  
  700. Note: Do Not use FirstTimeFlag in a PickActionScript or any other defered / delayed call as it's not valid after the main code executes. If you realy do need it under these conditions, copy it to the NSVar frame and remember to nil out that var after use.
  701.  
  702.  
  703. 7.7 LastEditField,LastEditDb
  704.  
  705. LastEditField  and LastEditDb vars
  706.  
  707.  
  708. Vars that hold the field number and database number of the last field that was edited. Set only when data was changed in an edit. Useful for detecting that some data on the screen changed if you need to know that to update other data. ie update a Total if a field holding the number to be totaled changed.
  709.  
  710.  
  711. 7.8 NsError
  712.  
  713. NsError
  714.  
  715. a var that is NIL if a no error has occured. Set to a non NIL value if a preceeding function (as the ones defined above) found an error. You  need to set to NIL if you need to detect further errors. See the list of values that NsError can be in Appendex A.
  716.  
  717.  
  718. 7.9 NSDontClick
  719.  
  720. NSDontClick
  721.  
  722. Set this variable to TRUE so that a tap in the Newton script window won't make it act like a button. ie hilite and run the script.
  723.  
  724. With NSDontClick set to TRUE you will be able to select the text displayed and copy it to the clipboard.
  725.  
  726.  
  727. 7.10 RecordAction
  728.  
  729. RecordAction
  730.  
  731.  
  732. Lets you detect a user action of creating / deleting / duplicating a record.  
  733.  
  734. The Var RecordAction can be:
  735.  
  736. 'NewMain , 'DeleteMain , 'DupMain  for the record being shown - the Main record or:
  737.  
  738. 'NewIndirect , 'DeleteIndirect , 'DupIndirect for any indirect record linked to on the screen.
  739.  
  740. Example:
  741. if RecordAction <> 'NewMain then return;        // exists code if it the reason for the code executing was not because a new record was made.
  742.  
  743.  
  744. NOTE: There is a single quote in front of the values. They are symbols.
  745.  
  746.  
  747.  
  748. 7.11 UpdateFromNS
  749.  
  750. UpdateFromNS
  751.  
  752. A variable that can be examined to see if the script is being executed because some other script called UpDataDisplay, thus forcing all other Newton Script Screen Objects to also be executed.
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759. Appendex A - NsError values
  760. ===========================
  761.  
  762. The NsError var holds the error number for the last error detected. If it is nil, then no error was detected. Below is the list for error numbers, the routine that it would be generated in and what caused the error.
  763.  
  764. Error#     Routine                       Explanation
  765.  
  766.  1 - DbNameToNumber:                Db name is not a string.
  767.  2 - DbNameToNumber:                No Db exists for that name.
  768.  3 - FieldnameToNumber:             Field name is not a string.
  769.  4 - FieldnameToNumber:             No field exists for that name.
  770.  5 - GetCursor:                     Invalid Db number
  771.  6 - GetCursor:                     Invalid index number.
  772.  7-  GetCursor:                     Invalid cursor generated with parameters.
  773.  8 - GetDbIndirectRecord:           Db number out of range.
  774.  9 - GetDbIndirectRecord:           Problem finding a match record / record not found.
  775. 10 - GetEntry:                      Problem with Cursor, possibly invalid.
  776. 11 - GetField:                      Field number less than zero.
  777. 12 - GetField:                      Field number greated than number of fields in the record.
  778. 13 - GetFieldNames:                 Invalid Db number.
  779. 14 - GetFieldNames:                 Database does not exist.
  780. 15 - GetNamesInfo:                  Problem accessing the Names soup. Possible invalid Match data.
  781. 16 - MakeNote:                      Problem saving the text to the NotePad. Possible memory full.
  782. 17 - MatchData:                     Field number less than zero.
  783. 18 - MatchData:                     Entry is not a soup entry.
  784. 19 - MatchData:                     Match data is not a string.
  785. 20 - MatchData:                     Field number greated than number of fields in the record.
  786. 21 - NextEntry:                     Problem fetching entry. Possibly invalid cursor.
  787. 22 - ResetCursor:                   Problem reseting cursor. Possibly invalid cursor.
  788. 23 - SaveEntry:                     Problem saving the record. Possible store full.
  789. 24 - SetField:                      Db number is invalid.
  790. 25 - SetField:                      Entry is not a soup entry.
  791. 26 - SetField:                      Field number is less than zero.
  792. 27 - SetField:                      Field number greated than number of fields in the record.
  793. 28 - Show:                          Data is not a string.
  794. 29 - ToNumber:                      Data is not a string.
  795. 30 - ToNumber:                      Data does not contain a valid number. Or number too large or small.
  796. 31 - ToNumber:                      Data did not convert to a number.
  797. 32 - ToString:                      Data was not a valid text number.
  798. 33 - MatchData:                     Data in the field of the record was not a string.
  799. 34 - SaveEntry:                     Record is not a soup entry.
  800. 35 - GetField:                      Entry is not a soup entry.
  801. 36 - ToString:                      Data was not a number. ie a real or integer.
  802. 37 - ToString:                      Data was NIL. 
  803. 38 - ToNumber:                      String was longer than 32 chars.
  804.  
  805.  
  806.  
  807.  
  808.  
  809. Appendex B - Release notes:
  810.  
  811. 1.12 11/28/97
  812.  - added notes for FirstTimeFlag and CurrentDbCursor vars.
  813.  - added Index at start of text.
  814.  - rearainged topics, subtopics.
  815.  
  816. 1.11 - 10/26/97 
  817.  - added NsError #38.
  818.  
  819. 1.1 - 9/27/97
  820.  
  821. - FOR loop text had 'step', not 'by' for loop increment.
  822. - Changed GetDbIndirectRecord() parameters and return value.
  823. - Added NSDontClick variable. See: Run Script Always.
  824. - Added  UpdateFromNS variable.
  825. - Added  DataformClick variable information.
  826. - Changed NsError to return a number vs TRUE and added list of codes.
  827. - Added more information about UpDateDisplay.
  828. - Minor other changes and many explanations added / expanded.
  829.  
  830. -30-